<template>
  <div class="saleReport">
    <el-row :gutter="4" style="margin:10px 0px">
      <el-col :span="2"><el-button size="small" type="primary" @click="add">新增供应商</el-button> </el-col>
      <el-col :span="3">
           <el-input size="small" placeholder="按供应商编号查询" v-model="goodsNumber" class="input-with-select">
              <el-button @click="search('num')" slot="append" icon="el-icon-search"></el-button>
          </el-input>
      </el-col>
      <el-col :span="3">
           <el-input size="small" placeholder="按名称查询" v-model="goodsNumber" class="input-with-select">
              <el-button @click="search('num')" slot="append" icon="el-icon-search"></el-button>
          </el-input>
      </el-col>
      <el-col :span="7">
        <el-button size="small" @click="search('time')" type="primary">清空</el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-table :data="noticeData" style="width: 100%" border>
        <el-table-column type="index" label="序号" width="200" align="center" :index="indexSort"></el-table-column>
        <el-table-column prop="providerNo" label="供应商编号" align="center"></el-table-column>
        <el-table-column prop="providerName" label="供应商名称" align="center"></el-table-column>
        <el-table-column prop="businessLicence" label="营业执照" align="center">
            <template slot-scope="props">
                <img :src="props.row.businessLicence" alt="" width="50" height="70">
            </template>
        </el-table-column>
        <el-table-column prop="contact" label="联系人" align="center"></el-table-column>
        <el-table-column prop="phone" label="座机" align="center"></el-table-column>
        <el-table-column prop="cellPhone" label="手机号" align="center"></el-table-column>
        <el-table-column prop="email" label="邮箱" align="center"></el-table-column>
        <el-table-column prop="address" label="地址" align="center"></el-table-column>
        <el-table-column prop="level" label="等级" align="center"></el-table-column>
        <el-table-column prop="type" label="类型" align="center"></el-table-column>
        <el-table-column prop="days" label="结算周期" align="center"></el-table-column>
        <el-table-column prop="notes" label="备注" align="center"></el-table-column>
        <el-table-column prop="updateDate" label="更新时间" align="center"></el-table-column>
        <el-table-column prop="" label="操作" align="center" width="200">
          <template slot-scope="scope">
            <span
              class="el-tag el-tag--warning el-tag--small"
              style="cursor: pointer;"
              @click="modify(scope.row)"
              size="mini"
            >修改</span>
            <span
              class="el-tag el-tag--danger el-tag--small"
              style="cursor: pointer;"
              @click="del(scope.row)"
              size="mini"
            >删除</span>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row style="text-align: right;">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[15, 50, 100, 200]"
        :page-size="pageSize"
        layout="->, sizes, prev, pager, next, jumper, total"
        :total="totalElements"
      ></el-pagination>
    </el-row>
    <addOrEdit :off.sync="supplierDialog" :rowData="rowdata" :title="title"></addOrEdit>
  </div>
</template>

<script>
import { getSupplierList,delSupplier } from "@/api/jxc/supplier.js";
import * as util from "@/util/util.js";
export default {
  name: "info",
  components: {
      "addOrEdit": () => import("./addOrEdit")
  },
  data() {
    return {
        goodsNumber: "",
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      selectDate: "",
      noticeData: [],
      pageSize: 15,
      currentPage: 1,
      totalElements: 0,
      totalPages: 1,
      supplierDialog: false,
      rowdata: {},
      title: ""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    modify(row){
     console.log(row);
      this.title = "修改供应商";
      this.rowdata = row;
      this.supplierDialog = true;
    },
    add() {
      this.title = "新增供应商";
      this.supplierDialog = true;
    },
    del(row) {
      console.log("row", row);
      delSupplier({ providerId: row.providerId }).then(
        res => {
          this.$notify.success("删除成功");
          this.getList();
        },
        err => {}
      );
    },
    getList() {
      getSupplierList({
        currentPage: this.currentPage,
        pageSize: this.pageSize
      }).then(
        res => {
          console.log("res商超销售接口", res);
          this.noticeData = res.data.list;
          this.noticeData.forEach(e => {
            e.createDate = util.timestampToTime(e.createDate);
            if (e.notificationType == 1) {
              e.notificationType = "店铺平台通知";
            } else {
              e.notificationType = "区域平台通知";
            }
          });
          this.totalElements = res.data.total;
        },
        err => {}
      );
    },
    //序号
    indexSort(index) {
      if (this.currentPage > 1) {
        index = (this.currentPage - 1) * this.pageSize + index + 1;
      } else {
        index = index + 1;
      }
      return index;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList();
      console.log(`当前页: ${val}`);
    }
  }
};
</script>

<style lang="less" props>
.pushList {
}
</style>